home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / hacking / virriiorg / unwho.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-23  |  993 b   |  46 lines

  1. /* This program removes utmp entries by name or number */
  2.  
  3. #include <utmp.h>
  4. #include <stdio.h>
  5. #include <sys/file.h>
  6. #include <sys/fcntlcom.h>
  7.  
  8. void usage(name)
  9. char *name;
  10. {
  11.     printf(stdout, "Usage: %s [ user ] or [ tty ]\n", name);
  12.     exit(1);
  13. }
  14.  
  15. main(int argc, char **argv)
  16. {
  17.     int fd;
  18.     struct utmp utmp;
  19.     int size;
  20.     int match, tty = 0;
  21.  
  22.     if (argc!=2)
  23.        usage(argv[0]);
  24.  
  25.     if ( !strncmp(argv[1],"tty",3) )
  26.        tty++;
  27.  
  28.     fd = open("/etc/utmp",O_RDWR);
  29.     if (fd >= 0)
  30.     {
  31.        size = read(fd, &utmp, sizeof(struct utmp));
  32.        while ( size == sizeof(struct utmp) )
  33.        {
  34.           if ( tty ? ( !strcmp(utmp.ut_line, argv[1]) ) :
  35.             ( !strcmp(utmp.ut_name, argv[1]) ) )
  36.           {
  37.              lseek( fd, -sizeof(struct utmp), L_INCR );
  38.              bzero( &utmp, sizeof(struct utmp) );
  39.              write( fd, &utmp, sizeof(struct utmp) );
  40.           }
  41.           size = read( fd, &utmp, sizeof(struct utmp) );
  42.        }
  43.     }
  44.     close(fd);
  45. }
  46.